<template>
    <div class='home-recommond'>
        <h3>官方歌单</h3>
        <div class="wrapper" ref="wrapper">
            <!-- 滚动所需的容器 -->
            <ul class="content" ref="content">
                <li v-for="(item,index) in listData" :key="index" @click="selectItem(item)">
                    <div class="cover">
                        <van-image :src="item.cover" radius="1rem" />
                        <span>{{item.listen_num | numFilter(1)}}万</span>
                    </div>
                    <span>{{item.title}}</span>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import { betterScrollHorizontal } from '@/common/betterScroll'
export default {
    name: 'HomeRecommond',
    data() {
        return {
            listData: []
        }
    },
    created() {
        this.getSongListData()
    },
    methods: {
        getSongListData() {
            this.$request('get', '/recommend/playlist/u')
                .then((res) => {
                    // console.log(res)
                    if (res.result == 100) {
                        this.listData = res.data.list
                    }
                    betterScrollHorizontal(
                        this,
                        this.$refs.wrapper,
                        this.$refs.content,
                        this.listData.length,
                        10) //调用横向滚动的方法
                })
        },
        selectItem(item) {
            let id = item.content_id
            this.$router.push({
                name: "SongList",
                params: { id }
            })
        }
    },
}
</script>
<style scope>
h2 {
    margin-left: 0.2rem;
}

.wrapper {
    width: 100%;
    overflow: hidden;
}

ul.content li {
    display: inline-block;
    width: 10rem;
    vertical-align: top;
}

ul.content li * {
    margin: 0.1rem;
}

ul.content li>span {
    display: inline-block;
    width: 100%;
    font-size: 0.8rem;
    color: #54493B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cover>span {
    position: absolute;
    right: 0.2rem;
    bottom: 0.3rem;
    background-color: rgba(255, 255, 255, .4);
    color: white;
    font-size: 14px;
    border-radius: 1rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    box-sizing: border-box;

    display: inline-block;
}

.cover {
    position: relative;
}
</style>